<layout name="layout" />
<div class="main-div">
    <form name="main_form" method="POST" action="__SELF__" enctype="multipart/form-data">
        <table cellspacing="1" cellpadding="3" width="100%">
            <tr>
                <td class="label3" style="width: 45%">角色名称：</td>
                <td>
                    <input  type="text" name="role_name" value="" />
                </td>
            </tr>
            <tr>
                <td class="label3">权限列表：</td>
                <td>
                   <foreach name="priData" item="v" key ='k'>
                       <?php echo str_repeat('-',8*$v['level'])?>
                       <input  level_id="{$v.level}" type="checkbox" name="pri_id[]" value="{$v.id}"/>
                       {$v.pri_name}
                       <br/>
                       </foreach>
                </td>
            </tr>
            <tr>
                <td colspan="99" align="center">
                    <input type="submit" class="button" value=" 确定 " />
                    <input type="reset" class="button" value=" 重置 " />
                </td>
            </tr>
        </table>
    </form>
</div>


<script>
    $(":checkbox").click(function () {
        var tmp_level_id = level_id = $(this).attr('level_id');
        if($(this).prop('checked')){
            $(this).nextAll(":checkbox").each(function (k,v) {
                if($(v).attr("level_id") >level_id)
                $(v).prop("checked","checked");
                else
                    return false;
            });
            $(this).prevAll(":checkbox").each(function (k,v) {
                if($(v).attr("level_id")<tmp_level_id){
                    $(v).prop("checked","checked");
                    tmp_level_id--;
                }
            });
        }else{
            $(this).nextAll(":checkbox").each(function (k,v) {
               if($(v).attr('level_id')>level_id)
                   $(v).removeAttr("checked");
                   else
                       return false;
            })
        }
    });
</script>